package com.wwwarehouse.resource_center.customView;

import android.content.Context;
import android.support.annotation.StringDef;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.wwwarehouse.resource_center.R;


/**
 * @author Joseph on 2017/9/27.
 *         <p/>
 *         商品,商店,工具,仓库,资源详细,页面动态切换
 *         <p>
 *         物的分类：H_GOODS(商品)、H_TOOL(工具)、H_SHOP(店铺)、H_STOCK(仓库)、
 *         资源的分类：H_SALE(供货)、H_STORE(仓储)、H_LABOUR(劳务)、H_PROCESS(加工)、H_SELL(销售)、H_TRANSPORT(运输)
 */

public class InfomationShowTypeView extends FrameLayout {

    public final static String H_GOODS = "H_GOODS";
    public final static String H_TOOL = "H_TOOL";
    public final static String H_SHOP = "H_SHOP";
    public final static String H_STOCK = "H_STOCK";
    public final static String H_SALE = "H_SALE";
    public final static String H_STORE = "H_SALE";
    public final static String H_LABOUR = "H_SALE";
    public final static String H_PROCESS = "H_SALE";
    public final static String H_SELL = "H_SALE";
    public final static String H_TRANSPORT = "H_SALE";
    public final static String H_RESOURCES = "H_RESOURCES";
    private String state;
    private Context mContext;
    private View HGOODS;  //商品
    private View HTOOLS;   //工具
    private View HSHOP;    //店铺
    private View HSTOCK;    //仓库
    private View RESOURCES; //资源

    public InfomationShowTypeView( Context context) {
        super(context);
        this.mContext = context;
    }

    public InfomationShowTypeView( Context context,  AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
    }

    public InfomationShowTypeView( Context context,  AttributeSet attrs,int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        if (getChildCount() > 1) {
            throw new IllegalStateException("InfomationShowTypeView can host only one direct child");
        }
        build();
    }

    private void build() {
        HGOODS = LayoutInflater.from(mContext).inflate(R.layout.fragment_create_goods, null);
        HTOOLS = LayoutInflater.from(mContext).inflate(R.layout.fragment_create_tools, null);
        HSHOP = LayoutInflater.from(mContext).inflate(R.layout.fragment_create_store, null);
        HSTOCK = LayoutInflater.from(mContext).inflate(R.layout.fragment_create_warehouse, null);
        RESOURCES = LayoutInflater.from(mContext).inflate(R.layout.fragment_create_res, null);
        this.addView(HGOODS);
        this.addView(HTOOLS);
        this.addView(HSHOP);
        this.addView(HSTOCK);
        this.addView(RESOURCES);
    }

    public void setStatus(@Flavour String status) {

        this.state = status;

        switch (status) {
            case H_GOODS:
                HGOODS.setVisibility(View.VISIBLE);
                HTOOLS.setVisibility(View.GONE);
                HSHOP.setVisibility(View.GONE);
                HSTOCK.setVisibility(View.GONE);
                RESOURCES.setVisibility(View.GONE);
                break;

            case H_TOOL:
                HGOODS.setVisibility(View.GONE);
                HTOOLS.setVisibility(View.VISIBLE);
                HSHOP.setVisibility(View.GONE);
                HSTOCK.setVisibility(View.GONE);
                RESOURCES.setVisibility(View.GONE);
                break;

            case H_SHOP:
                HGOODS.setVisibility(View.GONE);
                HTOOLS.setVisibility(View.GONE);
                HSHOP.setVisibility(View.VISIBLE);
                HSTOCK.setVisibility(View.GONE);
                RESOURCES.setVisibility(View.GONE);
                break;

            case H_STOCK:
                HGOODS.setVisibility(View.GONE);
                HTOOLS.setVisibility(View.GONE);
                HSHOP.setVisibility(View.GONE);
                HSTOCK.setVisibility(View.VISIBLE);
                RESOURCES.setVisibility(View.GONE);
                break;
            case H_RESOURCES:
                HGOODS.setVisibility(View.GONE);
                HTOOLS.setVisibility(View.GONE);
                HSHOP.setVisibility(View.GONE);
                HSTOCK.setVisibility(View.GONE);
                RESOURCES.setVisibility(View.VISIBLE);
                break;

            default:
                break;
        }
    }

    @StringDef({H_GOODS, H_TOOL, H_SHOP, H_STOCK, H_RESOURCES})
    public @interface Flavour {

    }
}
